package com.hirisun.faces.components;

import javax.faces.FacesException;
import javax.faces.component.UIComponent;
import javax.faces.component.html.HtmlCommandButton;
import javax.faces.event.ActionListener;

public class ProcessButton extends HtmlCommandButton {
	static public final String COMPONENT_TYPE = "com.hirisun.faces.ProcessButton";

	private ProcessForm processForm;

	public ProcessButton() {
		super();
		ActionListener listener = new ProcessButtonActionListener();
		addActionListener(listener);

	}

	public ProcessForm getProcessForm() {
		if (processForm != null) {
			return processForm;
		}

		UIComponent component = getParent();

		do {
			if (component instanceof ProcessForm) {
				processForm = (ProcessForm) component;
				return processForm;
			}
			component = component.getParent();
		} while (component != null);
		throw new FacesException(
				"Task form buttons must be includede within a task form");
	}

}
